import { request } from '@/service/request';

/** 获取外呼任务列表 */
export function fetchGetOutboundTaskList(params?: Api.Outbound.TaskSearchParams) {
  return request<Api.Outbound.TaskList>({
    url: '/outbound/task/list',
    method: 'get',
    params
  });
}

/** 获取外呼任务详情 */
export function fetchGetOutboundTask(taskId: CommonType.IdType) {
  return request<Api.Outbound.Task>({
    url: `/outbound/task/${taskId}`,
    method: 'get'
  });
}

/** 新增外呼任务 */
export function fetchCreateOutboundTask(data: Api.Outbound.TaskOperateParams) {
  return request<boolean>({
    url: '/outbound/task',
    method: 'post',
    data
  });
}

/** 修改外呼任务 */
export function fetchUpdateOutboundTask(data: Api.Outbound.TaskOperateParams) {
  return request<boolean>({
    url: '/outbound/task',
    method: 'put',
    data
  });
}

/** 删除外呼任务 */
export function fetchDeleteOutboundTask(taskIds: CommonType.IdType[]) {
  return request<boolean>({
    url: `/outbound/task/${taskIds.join(',')}`,
    method: 'delete'
  });
}

/** 暂停外呼任务 */
export function fetchPauseOutboundTask(taskId: CommonType.IdType) {
  return request<boolean>({
    url: `/outbound/task/${taskId}/pause`,
    method: 'post'
  });
}

/** 恢复外呼任务 */
export function fetchResumeOutboundTask(taskId: CommonType.IdType) {
  return request<boolean>({
    url: `/outbound/task/${taskId}/resume`,
    method: 'post'
  });
}

/** 终止外呼任务 */
export function fetchStopOutboundTask(taskId: CommonType.IdType) {
  return request<boolean>({
    url: `/outbound/task/${taskId}/stop`,
    method: 'post'
  });
}

/** 同步任务状态 */
export function fetchSyncOutboundTaskStatus(taskId: CommonType.IdType) {
  return request<boolean>({
    url: `/outbound/task/${taskId}/sync-status`,
    method: 'post'
  });
}

/** 批量添加号码到任务 */
export function fetchBatchAppendPhones(taskId: CommonType.IdType, phoneList: Api.Outbound.PhoneParam[]) {
  return request<boolean>({
    url: `/outbound/task/${taskId}/append-phones`,
    method: 'post',
    data: phoneList
  });
}

/** 同步任务详情数据 */
export function fetchSyncOutboundTaskDetail(taskId: CommonType.IdType) {
  return request<boolean>({
    url: `/outbound/task/${taskId}/sync-detail`,
    method: 'post'
  });
}

/** 导出外呼任务 */
export function fetchExportOutboundTask(params: Api.Outbound.TaskSearchParams) {
  return request<any>({
    url: '/outbound/task/export',
    method: 'post',
    data: params,
    responseType: 'blob'
  });
}
